var operationFlag = "";
var url = "";
var data =  "";
var link_to = "";
var pageflag = "";
var pageSize = "";
var tempPage = 0;
var checkboxcount = 0;
var checkboxsum = 0 ;
function pageselectCallback(page_id) {
	if(pageflag == "question"||pageflag == "questiondraft"){
		findAllQuestionList(page_id);
		tempPage = page_id;
	}else if(pageflag == "answer"){
		findAllAnswerList(page_id);
	}else if(pageflag == "questioncomm"){
		findAllQuestioncommList(page_id);
	}else if(pageflag == "questionfavorite"){
		findAllQuestionfavoriteList(page_id);
	}else if(pageflag == "questionassigned"){
		findAllQuestionassigned(page_id);
	}else if(pageflag == "usruser"){
		findAllUsr_userNotFriendByPage(page_id);
	}
	
}
function findAllUsr_userNotFriendByPage(pageindx){
	
	pageSize = 2;
	url = "findAllUsr_userNotFriendByPage";
	data =  "page.page=" + (pageindx + 1) + "&page.pageSize=" + pageSize;
	var search_user =  $("#search_user").attr("value");
	if(search_user=="user"||search_user==""){
		search_user = "";
	}
	data = data + "&jsonData.jsonData="+search_user;
	link_to = "view/question/viewUser.jsp#";
	pageflag = "usruser";
	page(pageindx , url , data , pageflag , link_to , pageSize);
}


function findAllQuestionassigned(pageindx){
	pageSize = 2;
	url = "findBzn_questionassignedByUser";
	data =  "page.page=" + (pageindx + 1) + "&page.pageSize=" + pageSize;
	link_to = "view/question/viewQuestionassigned.jsp#";
	pageflag = "questionassigned";
	page(pageindx , url , data , pageflag , link_to , pageSize);
}
function findAllQuestionList(pageindx){
	var search = "";
	var flag = $("#flag").attr("value");
	var questionFollowFlag = $("#question-follow-flag").attr("value");
	pageSize = 2;
	url = "findAllBzn_questionByPage";
	data =  "page.page=" + (pageindx + 1) + "&page.pageSize=" + pageSize+"&bzn_question.flag="+flag;
	// question or question draft 
	if(flag==0){
		pageflag = "question";
		link_to = "view/question/viewQuestion.jsp?flag=0#";
		search = $("#search-ask-input").attr("value") ;
		category = $("#category_id").attr("value" );
		//all question or question draft
		if(questionFollowFlag === undefined||questionFollowFlag == 'question'){
			//compare my question tab in left and all question in center
			//my question and no search
			if(search === undefined){
				search = "";
				link_to = "view/question/viewQuestiondraft.jsp?flag=0#";
				data = data + "&bzn_question.usr_user.id="+$("#userId").attr("value")+"&page.flag=concern";
			//all question and search
			}else if(search == searchTopicsOrQuestionOrMan){
				search = "";
			}
		//my concern and search
		}else if(questionFollowFlag == 'follow'){
			pageflag = questionFollowFlag;
			if(search == searchTopicsOrQuestionOrMan){
				search = "";
			}
			url = "findAllBzn_questionfollowByPage";
			data = data + "&bzn_question.usr_user.id="+$("#userId").attr("value")+"&page.flag=concern";
		}
		//category
		if(category === undefined){
			data = data+"";
		}else if(category != 'category_id' ){
			data = data + "&bzn_question.bsc_category.id="+category;
		}
		
		
	}else if(flag==1){
		search="";
		pageflag = "questiondraft";
		link_to = "view/question/viewQuestiondraft.jsp?flag=1#";
		data = data + "&page.flag=concern";
	}
	data = data + "&bzn_question.title="+search;
	page(pageindx , url , data , pageflag , link_to , pageSize);
}

function allQuestionOrMyConcern(str){
	$("#search-ask-input").attr("value" , searchTopicsOrQuestionOrMan) ; 
	$("#question-follow-flag").attr("value" , str) ; 
	$("#category_id").attr("value" , "category_id");
	findAllQuestionList(0);
}

function findQuestionByCategory(category_id){
	$("#category_id").attr("value" , category_id);
	findAllQuestionList(0);
}

function findAllQuestionfavoriteList(pageindx){
	pageSize = 2;
	url = "findAllBzn_questionfavoriteByPage";
	data =  "page.page=" + (pageindx + 1) + "&page.pageSize=" + pageSize+"&bzn_questionfavorite.bzn_questionfavgroup.id="+$("#favgroup_id").attr("value");
	link_to = "view/question/viewFavorite.jsp#";
	pageflag = "questionfavorite";
	page(pageindx , url , data , pageflag , link_to , pageSize);
}

function findQuestionByFavgroup(favgroup_id){
	$("#favgroup_id").attr("value" , favgroup_id);
	findAllQuestionfavoriteList(0);
}

function findAllAnswerList(pageindx){
	pageSize = 3;
	url = "findAllBzn_answerByPage";
	data =  "page.page=" + (pageindx + 1) + "&page.pageSize=" + pageSize;
	link_to = "view/question/viewQuestionDetail.jsp#";
	pageflag = "answer";
	page(pageindx , url , data , pageflag , link_to , pageSize);
}

function findAllQuestioncommList(pageindx){
	pageSize = 3;
	url = "findAllBzn_questioncommByPage";
	data =  "page.page=" + (pageindx + 1) + "&page.pageSize=" + pageSize;
	link_to = "view/question/viewQuestionDetail.jsp#";
	pageflag = "questioncomm";
	page(pageindx , url , data , pageflag , link_to , pageSize);
}


function page(pageindx , url , data , pageflag , link_to , pageSize) {
	var pageCount = "";
	/*$("#question-list").append("<img src='view/question/image2/icon/deleteIcon.png' alt='' />");
	setTimeout(function() {==ajax== },1000);
	*/
	$.ajax({
				contentType : "application/x-www-form-urlencoded; charset=utf-8",
				type : "POST",
				dataType : "json",
				url : url+".action",
				async : false,
				data : data,
				beforeSend : function() {
					$("#question-list").empty();	
					$("#Pagination").hide();
				},
				complete : function() {
					$("#divload").hide();
					
				},
				error : function() {
					window.location.replace("../login.jsp");
					//alert("errorpage");
				},
				success : function(json) {
					pageCount = json[0];
					if (pageCount == 0) {
						$("#Pagination").hide();
						
					}else{
						$("#Pagination").show();
					}
					if(pageflag=='questionfavorite'){
						var favname = json[1][0];
						var favdesc = json[1][1];
						var favid = json[1][2];
						if(favid==null){
							$("#label_fav_name").text(notGroup);
							$("#label_fav_desc").text(notGroup);
							selectData("fav-dir-sel","fav-dir-sel","findBzn_questionfavgroupList","" );
							$("#fav-dir-sel option[value='notGroup']").remove();
							
						}else{
							$("#label_fav_name").text(favname);
							$("#label_fav_desc").text(favdesc);
							selectData("fav-dir-sel","fav-dir-sel","findBzn_questionfavgroupList","bzn_questionfavorite.bzn_questionfavgroup.id="+favid );
						};
						$("#fav-dir-sel option[value='addToDirectory']").attr('selected',true);
						$("#check_all").attr("checked",false);
					}
					$.each(json,function(i, n) {
						
						var str = "";
							if (i>0) {
								if(pageflag=='question'){
									str ="<div class='single-question'>"+
									"<a class='q-head' href='#'><img src='view/question/image/p1.gif' alt='"+   hereIsTheHead +"' /> </a>"+
									"<div class='q-content'><div class='source'><a class='info' href='#'> "+n[2]+"</a> <span>"+shangHai+
									"</span><span>"+theTestArchitect+"</span> <span class='time'> "+n[5]+"</span>"+
									"</div><div class='clear'></div><div class='question-title'><a href='findBzn_questionById.action?bzn_question.id="+n[3]+"' target='_blank'> "+ n[0] +
									"</a></div><div ><div id='question-content-"+n[3]+"'>"+n[1]+
									"</div><div id='question-content-short-"+n[3]+"'  style='display:none'></div><div><div id='question-detail-"+n[3]+"'><a  style='cursor:hand' onclick='subShow("+n[3]+")' >More details</a></div><div id='question-simple-"+n[3]+"' style='display:none'>" +
									"<a style='cursor:hand' onclick='subShow("+n[3]+")' >Pack up</a></div></div><div class='tool-bar' >";
									if(n[8]=="noconcern"){
										str = str + "";
									}else if(n[8]=="cancelconcern"){
										str = str + "<a id='concern_del"+n[3]+"' style='cursor:hand' onclick='concernShowOrHide("+n[3]+")'><input type='hidden' id='hidden_concern_del"+n[3]+"' value='"+n[7]+"'/> " +
												"<input type='hidden' id='hidden_concern_add"+n[3]+"' value='"+n[3]+"'/> <img src='view/question/image/icon/add.png' alt='' />&nbsp;"+cancelConcern+"</a><a id='concern_add"+n[3]+"' style='display:none;cursor:hand' onclick='concernShowOrHide("+n[3]+")'> <img src='view/question/image/icon/add.png' alt='' />&nbsp;"+concern;
									}else{
										str = str + "<a id='concern_add"+n[3]+"' style='cursor:hand' onclick='concernShowOrHide("+n[3]+")'> <input type='hidden' id='hidden_concern_del"+n[3]+"' value='"+n[7]+"'/> " +
												"<input type='hidden' id='hidden_concern_add"+n[3]+"' value='"+n[3]+"'/><img src='view/question/image/icon/add.png' alt='' />&nbsp;"+concern+"</a><a  id='concern_del"+n[3]+"' style='display:none;cursor:hand'  onclick='concernShowOrHide("+n[3]+")'> <img src='view/question/image/icon/add.png' alt='' />&nbsp;"+cancelConcern;
									}
									str = str +"</a> <a    href='findBzn_questionById.action?bzn_question.id="+n[3]+"' target='_blank'> <img src='view/question/image/icon/ans.png' alt='' />&nbsp;"+
									reply+"</a> <a href='findBzn_questionById.action?bzn_question.id="+n[3]+"' target='_blank'> <img src='view/question/image/icon/comment.gif' alt='' />&nbsp;"+
									comment+"</a>  <img src='view/question/image/icon/share.png' alt='' />&nbsp;"+
									share+" <a href='#TB_inline?height=200&width=400&inlineId=fav-messagebox' title='Question' class='thickbox'type='button'   style='cursor:hand'onclick='initFav("+n[3]+")' > <img src='view/question/image/icon/flag.png' alt='' />&nbsp;"+
									collection+"</a> <a href='findBzn_questionById.action?bzn_question.id="+n[3]+"' target='_blank'> <img src='view/question/image/icon/editIcon.gif' alt='' />&nbsp;"+
									edit+"</a>";
									if(n[8]=="noconcern"){
										str = str +" <a href= 'delBzn_question.action?bzn_question.id="+n[3]+"&page.flag="+$('#page_flag').attr('value')+"&bzn_question.flag="+$('#flag').attr('value')+"'> <img src='view/question/image/icon/deleteIcon.png' alt='' />&nbsp;"+
										deleteData+"</a>";
									}
									str = str + "</div></div></div><div class='clear'></div></div>";
									
								}else if(pageflag=='follow'){
									str ="<div class='single-question'>"+
									"<a class='q-head' href='#'><img src='view/question/image/p1.gif' alt='"+   hereIsTheHead +"' /> </a>"+
									"<div class='q-content'><div class='source'><a class='info' href='#'> "+n[2]+"</a> <span>"+shangHai+
									"</span><span>"+theTestArchitect+"</span> <span class='time'> "+n[5]+"</span>"+
									"</div><div class='clear'></div><div class='question-title'><a href='findBzn_questionById.action?bzn_question.id="+n[3]+"' target='_blank'> "+ n[0] +
									"</a></div><div ><div id='question-content-"+n[3]+"'>"+n[1]+
									"</div><div id='question-content-short-"+n[3]+"'  style='display:none'></div><div><div id='question-detail-"+n[3]+"'><a  style='cursor:hand' onclick='subShow("+n[3]+")' >More details</a></div><div id='question-simple-"+n[3]+"' style='display:none'>" +
									"<a style='cursor:hand' onclick='subShow("+n[3]+")' >Pack up</a></div></div><div class='tool-bar' >"+
									"</a> " ;
									if(n[6]=="cancelconcern"){
										str = str + "<a id='concern_del"+n[3]+"' style='cursor:hand' onclick='cancelFollow("+n[3]+")'><input type='hidden' id='hidden_concern_del"+n[3]+"' value='"+n[7]+"'/> " +
										"<img src='view/question/image/icon/add.png' alt='' />&nbsp;"+cancelConcern+"</a>";
									}
									str = str + "</a><a    href='findBzn_questionById.action?bzn_question.id="+n[3]+"' target='_blank'> <img src='view/question/image/icon/ans.png' alt='' />&nbsp;"+
									reply+"</a> <a href='findBzn_questionById.action?bzn_question.id="+n[3]+"' target='_blank'> <img src='view/question/image/icon/comment.gif' alt='' />&nbsp;"+
									comment+"</a> <a href='#'> <img src='view/question/image/icon/share.png' alt='' />&nbsp;"+
									share+"</a> <a href='#TB_inline?height=550&width=600&inlineId=fav-messagebox' title='Question' class='thickbox'  type='button'> <img src='view/question/image/icon/flag.png' alt='' />&nbsp;"+
									collection+"</a> <a href='findBzn_questionById.action?bzn_question.id="+n[3]+"' target='_blank'> <img src='view/question/image/icon/editIcon.gif' alt='' />&nbsp;"+
									edit+"</a>";
									if(n[6]=="cancelconcern"){
										str = str +"";
									}else{
										str = str +" <a href= 'delBzn_question.action?bzn_question.id="+n[3]+"&page.flag="+$('#page_flag').attr('value')+"&bzn_question.flag="+$('#flag').attr('value')+"'> <img src='view/question/image/icon/deleteIcon.png' alt='' />&nbsp;"+
										deleteData+"</a>";
									}
									str = str +"</div></div></div><div class='clear'></div></div>";
								}else if(pageflag=='answer'){
									if(n[4]==null){
										n[4]=0;
									}else{
										n[4]=n[4].toFixed(2);
									}
									str ="<div class='single-question'>"+
									"<a class='q-head' href='#'><img src='view/question/image/p1.gif' alt='"+   hereIsTheHead +"' /> </a>"+
									"<div class='q-content'><div class='source'><a class='info' href='#'> "+n[1]+"</a> <span>"+shangHai+
									"	</span> <span> "+theTestArchitect+"</span><input type='hidden' value='"+n[5]+"' id='num_"+n[2]+"'/> <span class='time' id='rank_"+n[2]+"'>"+n[4]+" </span>"+
									"</div><div class='clear'></div>" +
									"<div><p><span id='span_answer"+n[2]+"'>"+n[0]+"</span></p>"+
									"<div class='tool-bar'>"+
									"<a href='javascript:void(0)' onclick='Goto("+n[2]+")'> <input type='hidden' id = 'hidden-question-content-"+n[2]+"' value='"+n[0]+"'/><img src='view/question/image/icon/ans.png' alt='' />&nbsp;"+
									quote +"</a><a  style='cursor:hand' onclick='initStar("+n[2]+")' > <img src='view/question/image/icon/comment.gif' alt='' />&nbsp;"+
									up +" </a> <img src='view/question/image/icon/share.png' alt='' />&nbsp;"+
									share+" </div></div></div><div class='clear'></div></div> ";
									/*<a href='#'> <img src='view/question/image/icon/deleteIcon.png' alt='' />&nbsp;"+
									deleteData+"</a><a href='#'> <img src='view/question/image/icon/editIcon.gif' alt='' />&nbsp;"+
									edit+"</a> */								
									}else if(pageflag=='questioncomm'){
										str ="<div class='single-question'>"+
										"<a class='q-head' href='#'><img src='view/question/image/p1.gif' alt='"+   hereIsTheHead +"' /> </a>"+
										"<div class='q-content'><div class='source'><a class='info' href='#'> "+n[1]+"</a> <span>"+shangHai+
										"	</span> <span> "+theTestArchitect+"</span> <span class='time'> "+n[5]+"</span>"+
										"</div><div class='clear'></div>" +
										"<div><p><span id=span_answer"+n[2]+">"+n[0]+"<span></p></div></div><div class='clear'></div></div>";
										
									}else if(pageflag=='questionfavorite'){
									if(i>1){
										str=" <tr><td><input type='checkbox' value= '"+n[2]+"' name= 'checkbox_fav' /></td>"+
										"<td><a href='findBzn_questionById.action?bzn_question.id="+n[0]+"' target='_blank'>"+n[1]+"</a></td>"+
										"<td><a href='#' title='title'>"+n[3]+"</a></td>"+
										"<td>"+n[5]+"</td>"+
										"<td>"+n[4]+"</td>"+
										"<td><a onclick=' delFavById("+ n[2]+")'><img src='#' alt='Edit' /></a></td>";/*+
										"<td><a href='#' title='Edit Meta'><img src='#' alt='Edit Meta' /></a></td> </tr>"*/
									}
								}else if(pageflag=='questiondraft'||pageflag=='questionassigned'){
									str ="<div class='single-question'>"+
									"<a class='q-head' href='#'><img src='view/question/image/p1.gif' alt='"+   hereIsTheHead +"' /> </a>"+
									"<div class='q-content'><div class='source'><a class='info' href='#'> "+n[2]+"</a> <span>"+shangHai+
									"	</span> <span> "+theTestArchitect+"</span> <span class='time'>"+n[5]+"</span>"+
									"</div><div class='clear'></div><div class='question-title'><a href='findBzn_questionById.action?bzn_question.id="+n[3]+"'> "+ n[0] +
									"</a></div><div ><div id='question-content-"+n[3]+"'>"+n[1]+
									"</div><div id='question-content-short-"+n[3]+"'  style='display:none'></div><div><div id='question-detail-"+n[3]+"'><a  style='cursor:hand' onclick='subShow("+n[3]+")' >More details</a></div><div id='question-simple-"+n[3]+"' style='display:none'><a style='cursor:hand' onclick='subShow("+n[3]+")' >Pack up</a></div></div><div class='tool-bar'>&nbsp;"+
									" <a href='findBzn_questionById.action?bzn_question.id="+n[3]+"'> <img src='view/question/image/icon/editIcon.gif' alt='' />&nbsp;"+
									edit+"</a> <a href = 'delBzn_question.action?bzn_question.id="+n[3]+"&page.flag="+$('#page_flag').attr('value')+"&bzn_question.flag="+$('#flag').attr('value')+"'> <img src='view/question/image/icon/deleteIcon.png' alt='' />&nbsp;"+
									deleteData+"</a></div></div></div><div class='clear'></div></div>";
								}else if(pageflag=='usruser'){
									if(i>1){
										str ="<div class='single-question'>"+
										"<a class='q-head' href='#'><img src='view/question/image/p1.gif' alt='"+   hereIsTheHead +"' /> </a>"+
										"<div class='q-content'><div class='source'><a class='info' href='#'> "+n[1]+","+n[2]+"</a> <span>"+shangHai+
										"	</span> <span> "+theTestArchitect+"</span> <span class='time'><a style='cursor:hand' onclick='initAddFri("+n[0]+")'>addfriend</a></span>"+
										"</div><div class='clear'></div><div class='question-title'><a href='findBzn_questionById.action?bzn_question.id="+n[3]+"'> "+ n[0] +
										"</a></div><div ><div >"+n[3]+
										"</div><div></div></div></div><div class='clear'></div></div>";
									
									
									}
								}
								
								
								
								
								$("#question-list").append(str);
								subShow(n[3]);
							}
							
							
						/*	onclick=subShow('question-content-70','question-content-short-70', 0*/
									});
					
				}// end of success

			});
	if (pageCount != 0) {
		$("#Pagination").pagination(pageCount, {
			callback : pageselectCallback,
			prev_text : '<< 上一页',
			next_text : '下一页 >>',
			items_per_page : pageSize,
			num_display_entries : 10,
			current_page : pageindx,
			num_edge_entries : 2,
			link_to : link_to

		});
	}
}

function questionSubmit(flag){
	//viewQuestion.jsp  draft or question   0:question 1:draft 
	if(flag=='question'){
		var str = "";
		$("input[name='checkbox_user_name']:checked").each(function(){
			str = str + this.value + ",";
		});
		$("#hidden_user").attr("value",str);
		$("#question_flag").attr("value","0");
		$("#question_content").attr("value" , editor.html());
		$("#question_form").submit();
	}else if(flag=='draft'){
		var str = "";
		$("input[name='checkbox_user_name']:checked").each(function(){
			str = str + this.value + ",";
		});
		$("#hidden_user").attr("value",str);
		$("#question_flag").attr("value","1");
		$("#question_content").attr("value" , editor.html());
		$("#question_form").submit();
	}else if(flag=='addtoquestion'){
		$("#question_flag").attr("value","0");
		$("#question_content_edit").attr("value" , editor.html());
		$("#question_form").submit();
	}else if(flag=='questioncomm_answer'){
		$("#question_content").attr("value" , editor.html());
		$("#question_form_qa").submit();
	}else {
		var str = "";
		$("input[name='checkbox_user_name']:checked").each(function(){
			str = str + this.value + ",";
		});
		$("#hidden_user").attr("value",str);
		$("#question_content_edit").attr("value" , editor.html());
		$("#question_form").submit();
	}
	
	
}

function changeSubmitAction(flag){
	if(flag=='reply'){
		findAllAnswerList(0);   
		$("#question_form_qa").attr("action","addBzn_answer.action");
		$("#question_content").attr("name","bzn_answer.content");
		$("#question_userid").attr("name","bzn_answer.usr_user.id");
		$("#question_id").attr("name","bzn_answer.bzn_question.id");
		$("#question_answer_flag").attr("value","reply");
		$("#question_answer").hide();
	}else if(flag=='comment'){
		findAllQuestioncommList(0);   
		$("#question_form_qa").attr("action","addBzn_questioncomm.action");
		$("#question_content").attr("name","bzn_questioncomm.content");
		$("#question_userid").attr("name","bzn_questioncomm.usr_user.id");
		$("#question_id").attr("name","bzn_questioncomm.bzn_question.id");
		$("#question_answer_flag").attr("value","comment");
		$("#question_answer").hide();
		
	}
	
}

function operationAction( url , data  ){

	$.ajax({
		contentType : "application/x-www-form-urlencoded; charset=utf-8",
		type : "POST",// 用POST方式传输
		dataType : "json",// 数据格式:JSON
		url : url+".action",// 目标地址
		data : data,
		async: false, 
		error : function() {
			alert("jsonerror_operation");
		},
		success : function(json) {
			if(json=="failure"){
				alert("It has been collected");
			}else if(json=="success"){
				alert("add successfully" );
			}else if(json=="success_edit"){
				alert("edit successfully" );
			}else if(json=="success_move"){
				alert("move successfully" );
			}else if(json=="success_del"){
				alert("move successfully" );
			}else if(json[1]=="follow_del"){
				alert("delete successfully" );
				$("#hidden_concern_add"+json[0]).attr("value" , json[0]);
				$("#hidden_concern_add").attr("value" , json[0]);
			}else if(json[1]=="follow_add"){
				alert("add successfully" );
				$("#hidden_concern_del"+json[2]).attr("value" , json[0]);
				$("#hidden_concern_del").attr("value" , json[0]);
			}else if(json[0]=="exist_comm"){
				alert("It has been comm" );
			}else if(json[0]=="notexist_comm"){
				tb_show("score","#TB_inline?height=200&width=350&inlineId=star_messagebox", null);
			}else if(json[0]=="sucess_comm"){
				alert("comm successfully");
				$("#rank_"+json[2]).text(parseInt(json[1]).toFixed(2));//json[1].toFixed(2)
			}else if(json[0]=="sucess_login"){
				window.location.replace("sucess.jsp");
			}else if(json[0]=="sucess_failed"){
				window.location.replace("login.jsp");
			}else if(json[0]=="sucess_logout"){
				window.location.replace("../login.jsp");
			}
		},	
		});
}

function addQuestionfavorite( ){
	var userId = $("#userId").attr("value");
	var sel = $("#fav-dir-sel").attr("value");
	data = "bzn_questionfavorite.bzn_question.id="+ $("#favques_id").attr("value")+"&bzn_questionfavorite.usr_user.id="+userId;
	if(sel != "addToDirectory"&&sel != "notGroup"){
		data = data + "&bzn_questionfavorite.bzn_questionfavgroup.id="+sel;
	}
	url = "addBzn_questionfavorite";
	operationAction(url , data);
	self.parent.tb_remove();
	
}

function operationQuestionfollow(questionId ,followId , oflag){
	//add or del questionfollow
	var userId = $("#userId").attr("value");
	if(oflag == "add"){
		url = "addBzn_questionfollow";
		data = "bzn_questionfollow.bzn_question.id="+questionId+"&bzn_questionfollow.usr_user.id="+userId;
	}else if(oflag == "del"){
		url = "delBzn_questionfollow";
		data = "bzn_questionfollow.id="+followId+"&bzn_questionfollow.bzn_question.id="+questionId;
	}else if(oflag == "follow_del"){
		url = "delBzn_questionfollow";
		data = "bzn_questionfollow.id="+followId;
	}
	operationAction(url , data);
	
}

function cancelFollow(id){
	operationQuestionfollow("" , $("#hidden_concern_del"+id).attr("value"), "follow_del");
	allQuestionOrMyConcern('follow');
}

function subShow(id){
	var num = 10;
	var objId =  $("#question-content-"+id);
	var objIdShort =  $("#question-content-short-"+id);
	var objString = objId.text();
	if(objId.is(":visible")&&objIdShort.is(":hidden")){
		objIdShort.text(objString.substring(0,num) + "..."); 
		objIdShort.show();
		objId.hide();
		$("#question-detail-"+id).show();
		$("#question-simple-"+id).hide();
		
	}else if(objId.is(":hidden")&&objIdShort.is(":visible")){
		objId.slideDown();
		objIdShort.slideUp();
		$("#question-detail-"+id).hide();
		$("#question-simple-"+id).show();
	}
	
	
}


function questionDraftEditorShow(){
	if($("#edit_content").is(":hidden")&&$("#show_content").is(":visible")){
		if(editor === undefined){}else{editor.remove("#question_content");}
		getKindEditor("question_content_edit" );  
	 	$("#edit_content").show();
		$("#show_content").hide();
		$("#question_answer").hide();
		setTimeout(function() {editor.html($("#question_content_hidden").attr("value")); },1000);
	}else{
		$("#edit_content").hide();
		$("#show_content").show();
	}
}

//show or hide question_content textarea
function questionShowOrHide( ){
	$("#edit_content").hide();
	$("#show_content").show();
	if(editor === undefined){}else{editor.remove("#question_content_edit");}
	objShowOrHide("question_answer");
	getKindEditor("question_content" );
	if(	$("#question_form_qa").attr("action")=="addBzn_questioncomm.action"){
		setTimeout(function() {editor.html("this is question comment"); },100);
	}else{
		setTimeout(function() {editor.html("this is answer"); },100);
	}
	
}

function Goto(str){
	if(str=='reply'||str=='comment'){
		changeSubmitAction(str);
	}else{
		if(editor === undefined){}else{editor.remove("#question_content_edit");}
		$("#question_answer").show();
		getKindEditor("question_content");
		setTimeout(function() {editor.html($("#hidden-question-content-"+str).attr("value")); },100);
	}
	window.location.hash='question_answer_flag';
	
}

function concernShowOrHide(id){
	//compare for viewQuestionDetail.jsp concern or cancel concern button
	if(id==undefined){
		id = "";
	}
	if($("#concern_add"+id).is(":hidden")&&$("#concern_del"+id).is(":visible")){
		operationQuestionfollow($("#hidden_concern_add"+id).attr("value") , $("#hidden_concern_del"+id).attr("value") , "del");
		$("#concern_add"+id).show();
		$("#concern_del"+id).hide();
	}else{
		operationQuestionfollow($("#hidden_concern_add"+id).attr("value") , $("#hidden_concern_del"+id).attr("value"), "add");
		$("#concern_add"+id).hide();
		$("#concern_del"+id).show();
		
	}
}

function operateFavgroup(flag_favgroup){
	data = "bzn_questionfavgroup.name="+$("#fav_name").attr("value")+"&bzn_questionfavgroup.description="+$("#fav_desc").attr("value");
	var fav_id = $("#favgroup_id").attr("value"); 
	if(fav_id == "" && flag_favgroup=='edit'){
		alert("can not edit");
	}else{
		if(flag_favgroup=='add'||flag_favgroup=='question_fav_add'){
			url = "addBzn_questionfavgroup";
		}else if(flag_favgroup=='edit'){
			url = "editBzn_questionfavgroup";
			data = data + "&bzn_questionfavgroup.id="+fav_id;
		}
		operationAction(url , data);
		if(flag_favgroup=='add'||flag_favgroup=='edit'){
			self.parent.tb_remove();
			selectData("fav-dir-list","fav-dir-list","findBzn_questionfavgroupList","" );
		}else{
			selectData("fav-dir-sel","fav-dir-sel","findBzn_questionfavgroupList","" );
			$("#fav-dir-messagebox").hide();
		}
		
		if(flag_favgroup=='edit'){
			$("#label_fav_name").text($("#fav_name").attr("value"));
			$("#label_fav_desc").text($("#fav_desc").attr("value"));
		}
		$("#fav_name").attr("value","");
		$("#fav_desc").attr("value","");
		
	}
}

function notFavGroup(){
	findQuestionByFavgroup("");   
	
}


function setFavGroup(flag_favgroup){
	if(flag_favgroup == 'add'||flag_favgroup == 'question_fav_add'){
		$("#fav_name").attr("value","");
		$("#fav_desc").attr("value","");
	}else if(flag_favgroup == 'edit'){
		$("#fav_name").attr("value",$("#label_fav_name").text());
		$("#fav_desc").attr("value",$("#label_fav_desc").text());
	}
	$("#button_favgroup").attr("onclick" , "operateFavgroup('"+flag_favgroup+"')");
}

function moveFav(){
	url = "editBzn_questionfavorite";
	var str = "";
	$("input[name='checkbox_fav']:checked").each(function(){
		str = str + this.value + ",";
	});
	if(str==""){
		alert("please tick some checkbox");
	}else{
		str = $("#fav-dir-sel").attr("value")+"<"+str;
		data = "jsonData.jsonData="+str;
		if($("#fav-dir-sel").attr("value")!= "addToDirectory"){
			operationAction(url , data);
			findQuestionByFavgroup($("#favgroup_id").attr("value"));
		}
	}
	
}

function tickAll(checkboxname){
	var obj = $("input[name='"+checkboxname+"']");
	if(obj.attr("checked")== undefined){
		obj.attr("checked",true);
	}else{
		obj.attr("checked",false);
	}
	
}

function delFavgroup(){
	var fav_id = $("#favgroup_id").attr("value"); 
	if(fav_id == ""){
		alert("can not delete");
	}else{
		url = "delBzn_questionfavgroup";
		data = "jsonData.jsonData="+fav_id+"<del&bzn_questionfavgroup.id="+fav_id;
		operationAction(url , data);
		window.location.href = "viewFavorite.jsp";
	}
}

function delFav(){
	url = "delBzn_questionfavorite";
	var str = "";
	$("input[name='checkbox_fav']:checked").each(function(){
		str = str + this.value + ",";
	});
	if(str==""){
		alert("please tick some checkbox");
	}else{
		data = "jsonData.jsonData="+str;
		operationAction(url , data);
		window.location.href = "viewFavorite.jsp";
	}

}
function delFavById(id){
	url = "delBzn_questionfavorite";
	data = "jsonData.jsonData="+id+",";
	operationAction(url , data);
	window.location.href = "viewFavorite.jsp";
}

function showFav(){
	objShowOrHide('fav-dir-messagebox');
	setFavGroup('question_fav_add');
}

function initFav(favques_id){
	$("#favques_id").attr("value" , favques_id);
	initThickbox();
}
function initThickbox(){
	tb_init('a.thickbox, area.thickbox, input.thickbox');  
}

function viewUser(){
	selectData("checkbox-user","checkbox-user","findUsr_friendList","page.page="+checkboxcount );
}





function initStar(id){
	$("#anscomm_ansid").attr("value",id);
	$("#anscomm_avg").attr("value",$("#rank_"+id).text());//average 
	$("#anscomm_num").attr("value",$("#num_"+id).attr("value"));
	url = "findBzn_answercommByUserIdAndAnsId";
	data = "bzn_answercomm.bzn_answer.id="+$("#anscomm_ansid").attr("value");
	operationAction(url , data);
	
}

function answercommSubmit(){
	url = "addBzn_answercomm";
	data = "bzn_answercomm.rank="+$("#anscomm_rank").attr("value")+"&bzn_answercomm.bzn_answer.id="+
	$("#anscomm_ansid").attr("value")+"&bzn_answercomm.content="+$("#anscomm_content").text();//
	operationAction(url , data);
	self.parent.tb_remove();
	
}

function spanUser(hiddenId , spanId){
	var str = ""; 
	var string = $("#"+hiddenId).attr("value");
	var arr = string.split(",");
	for(var i = 0 ; i < arr.length-1 ; i++ ){
		var arrname = arr[i].split("<");
		str = str + arrname[0]+",";
	}
	$("#"+spanId).text(str.substring(0, str.length-1));
}

function addFriend(){

	$("#addUsr_friend").submit();
	alert("add sucessfully");
	self.parent.tb_remove();
	self.parent.window.location.reload();  

}

function login(){
	url = "findUsr_userByNameAndPass";
	data = "usr_user.username="+$("#username").attr("value")+"&usr_user.password="+
	$("#password").attr("value")+"&jsonData.jsonData="+$("#verifycode").attr("value");
	operationAction(url , data);
}

function refreshVerifyCode(){
	 // document.getElementById('ref').src='view/user/verifycode.jsp?t='+new Date().getTime();
	$("#ref").attr("src","view/user/verifycode.jsp?t="+new Date().getTime());
	
}

function showFri(){
	objShowOrHide('fri-dir-messagebox');
	setFavGroup('question_fav_add');
}

//module : fri or fav
function showDirectory(module){
	objShowOrHide(module+"-dir-messagebox");
	setDirGroup(module , module+"_add");
}

function setDirGroup(module , flag_dirgroup){
	if(flag_dirgroup == 'add'||flag_dirgroup == module+'_add'){
		$("#"+module+"_name").attr("value","");
		$("#"+module+"_desc").attr("value","");
	}else if(flag_dirgroup == 'edit'){
		$("#"+module+"_name").attr("value",$("#label_"+module+"_name").text());
		$("#"+module+"_desc").attr("value",$("#label_"+module+"_desc").text());
	}
	$("#button_"+module+"group").attr("onclick" , "operateDirgroup('"+module+"','"+flag_dirgroup+"')");
}

function operateDirgroup(module,flag_dirgroup){
	if(module=="fav"){
		data = "bzn_questionfavgroup.name="+$("#fav_name").attr("value")+"&bzn_questionfavgroup.description="+$("#fav_desc").attr("value");
	}else if(module=="fri"){
		data = "usr_friendgroup.name="+$("#fri_name").attr("value")+"&usr_friendgroup.description="+$("#fri_desc").attr("value");
	} 
	//view friend.jsp or view my collection.jsp
	var group_id = $("#"+module+"group_id").attr("value"); 
	if(group_id == "" && flag_dirgroup=='edit'){
		alert("can not edit");
	}else{
		if(flag_dirgroup=="add"||flag_dirgroup==module+"_add"){
			if(module=="fav"){
				url = "addBzn_questionfavgroup";
			}else if(module=="fri"){
				url = "addUsr_friendgroup";
			}
		}else if(flag_dirgroup=='edit'){
			if(module=="fav"){
				url = "editBzn_questionfavgroup";
				data = data + "&bzn_questionfavgroup.id="+group_id;
			}
		}
		operationAction(url , data);
		if(flag_dirgroup=='add'||flag_dirgroup=='edit'){
			self.parent.tb_remove();
			if(module=="fav"){
				selectData(module+"-dir-list",module+"-dir-list","findBzn_questionfavgroupList","" );
			}else if(module=="fri"){
				selectData(module+"-dir-list",module+"-dir-list","findUsr_friendgroupList","" );
			}
		}else{
			if(module=="fav"){
				selectData(module+"-dir-sel",module+"-dir-sel","findBzn_questionfavgroupList","" );
			}else if(module=="fri"){
				selectData(module+"-dir-sel",module+"-dir-sel","findUsr_friendgroupList","" );
			}
			$("#"+module+"-dir-messagebox").hide();
		}
		
		if(flag_dirgroup=='edit'){
			$("#label_"+module+"_name").text($("#"+module+"_name").attr("value"));
			$("#label_"+module+"_desc").text($("#"+module+"_desc").attr("value"));
		}
		$("#"+module+"_name").attr("value","");
		$("#"+module+"_desc").attr("value","");
		
	}
}

function logout(){
	url = "delUsr_userBySesson";
	operationAction(url , "");
}
function testRepeatOperation(){
	setTimeout(function() {alert("======");},10000);
}
